package vnreal.evaluations.metrics;

import java.util.Iterator;

import vnreal.demands.CpuDemand;
import vnreal.mapping.Mapping;
import vnreal.network.substrate.SubstrateNode;
import vnreal.resources.AbstractResource;
import vnreal.resources.CpuResource;

public class CPUCyclesCost extends AbstractEvaluation {

	@Override
	public double calculate() {

		double nodeCost = 0;

		CpuDemand tmpCpuDem;

		for (Iterator<SubstrateNode> tmpNode = stack.getSubstrate().getVertices().iterator(); tmpNode.hasNext();) {
			SubstrateNode tmps = tmpNode.next();
			for (AbstractResource res : tmps) {
				if (res instanceof CpuResource) {
					for (Mapping f : res.getMappings()) {
						tmpCpuDem = (CpuDemand) f.getDemand();
						nodeCost += tmpCpuDem.getDemandedCycles();
					}
				}
			}
		}
		return nodeCost;
	}

	@Override
	public String toString() {

		return "CPUCyclesCost";
	}

}
